package ee.android.kinokavad.data;

import java.util.Locale;

import ee.android.kinokavad.utils.LogUtils.Logger;

public class Session {

	private long id;

	private long cinemaId;

	private long movieId;

	private String dateTime;

	private String pictureLink;

	private String movieTitle;
	
	private String cinemaName;
	
	private String duration;
	
	private String movieGenre;
	
	private boolean beforeNow;

	/**
	 * Constructor for database query.
	 * @param id
	 * @param cinemaId
	 * @param movieId
	 * @param dateTime
	 * @param pictureLink
	 */

	public Session(long id, long cinemaId, long movieId, String dateTime,
			String pictureLink) {
		this.id = id;
		this.cinemaId = cinemaId;
		this.movieId = movieId;
		this.dateTime = dateTime;
		this.pictureLink = pictureLink;
	}
	
	/**
	 * Construcor for database
	 * @param id
	 * @param cinemaId
	 * @param movieId
	 * @param dateTime
	 * @param pictureLink
	 * @param movieTitle
	 * @param duration
	 * @param movieGenre
	 */

	public Session(long id, long cinemaId, long movieId, String dateTime,
			String pictureLink, String movieTitle, String duration,
			String movieGenre) {
		super();
		this.id = id;
		this.cinemaId = cinemaId;
		this.movieId = movieId;
		this.dateTime = dateTime;
		this.pictureLink = pictureLink;
		this.movieTitle = movieTitle;
		this.duration = duration;
		this.movieGenre = movieGenre;
	}



	/**
	 * Constructor for NetworkUtils
	 * @param cinemaId
	 * @param movieId
	 * @param dateTime
	 * @param pictureLink
	 */

	public Session(long cinemaId, long movieId, String dateTime,
			String pictureLink) {
		this.cinemaId = cinemaId;
		this.movieId = movieId;
		this.dateTime = dateTime;
		this.pictureLink = pictureLink;
	}



	@Override
	public String toString() {
		return "Session [id=" + id + ", cinemaId=" + cinemaId + ", movieId="
				+ movieId + ", dateTime=" + dateTime + ", pictureLink="
				+ pictureLink + "]";
	}

	public long getId() {
		return id;
	}

	public long getCinemaId() {
		return cinemaId;
	}

	public long getMovieId() {
		return movieId;
	}

	public String getPictureLink() {
		return pictureLink;
	}

	public String getDateTime() {
		return dateTime;
	}

	public void setDateTime(String dateTime) {
		this.dateTime = dateTime;
	}

	public String getMovieTitle() {
		return movieTitle;
	}

	public void setMovieTitle(String movieTitle) {
		this.movieTitle = movieTitle;
	}

	public boolean isBeforeNow() {
		return beforeNow;
	}

	public void setBeforeNow(boolean beforeNow) {
		this.beforeNow = beforeNow;
	}

	public String getCinemaName() {
		return cinemaName;
	}

	public void setCinemaName(String cinemaName) {
		this.cinemaName = cinemaName;
	}

	public String getDuration() {
		try {
			if (duration != null && !duration.contains("h") 
					&& !duration.toLowerCase(Locale.ENGLISH).contains("n/a")) {
				String copy = duration.replace("min", "").replace(" ", "");
				int minutes = Integer.parseInt(copy);
				if (minutes < 60) return duration;
				
				int hours = minutes/60;
				return String.format(Locale.ENGLISH, "%d h %d min", hours, minutes % 60);
			}
		} catch (Exception e) {
			Logger.e("Session", "Failed to parse duration: " + duration);
		}
		return duration;
	}

	public void setDuration(String duration) {
		this.duration = duration;
	}

	public String getMovieGenre() {
		return movieGenre;
	}

	public void setMovieGenre(String movieGenre) {
		this.movieGenre = movieGenre;
	}

}
